/*
	klib_function_group_table.c

	contains the global function group table. This is used to work out the address of
	the function group's sub-function table for the requested group

	All KLIB functions assume that interrupts are enabled when called.

	Author: Aidan Goddard 18/8/13
*/

#include"headers/ktypes.h"
#include"headers/klib_proc_threads.h"
#include"headers/klib_page_alloc.h"
#include"headers/klib_message_passing.h"
#include"headers/klib_IRQ_control.h"
#include"headers/klib_keyboard_buffer.h"
#include"headers/klib_ACPI_tables.h"
#include"headers/klib_system_timers.h"
#include"headers/klib_system_resources.h"
#include"headers/klib_ACDM.h"
#include"headers/klib_PCIE.h"


// the page alloc table
uint64_t __KLIB__page_alloc_table[8] =
{
	0,
	(uint64_t)&__KLIB__AllocPage,
	(uint64_t)&__KLIB__DeallocPage,
	(uint64_t)&__KLIB__GetFreePageCount,
	(uint64_t)&__KLIB__MapPageForIO
};

// the proc_threads table
uint64_t __KLIB__proc_threads_table[16] =
{
	0,
	(uint64_t)&__KLIB__SpawnNewThread,
	(uint64_t)&__KLIB__KillThisThread,
	(uint64_t)&__KLIB__WaitThisThread,
	(uint64_t)&__KLIB__SleepThisThread,
	(uint64_t)&__KLIB__WakeThread,
	(uint64_t)&__KLIB__WakeThreadEx,
	(uint64_t)&__KLIB__KillThread,
	(uint64_t)&__KLIB__SpawnSystemProcess
};

// the message_passing table
uint64_t __KLIB__message_passing_table[16] =
{
	0,
	(uint64_t)&__KLIB__MSGAllocateChannel,
	(uint64_t)&__KLIB__MSGDeallocateChannel,
	(uint64_t)&__KLIB__MSGFindChannel,
	(uint64_t)&__KLIB__MSGClientBindChannel,
	(uint64_t)&__KLIB__MSGServerRead,
	(uint64_t)&__KLIB__MSGServerPeek,
	(uint64_t)&__KLIB__MSGClientRead,
	(uint64_t)&__KLIB__MSGClientPeek,
	(uint64_t)&__KLIB__MSGServerSendSync,
	(uint64_t)&__KLIB__MSGServerSendAsync,
	(uint64_t)&__KLIB__MSGClientSendSync,
	(uint64_t)&__KLIB__MSGClientSendAsync,
	(uint64_t)&__KLIB__MSGGetServerPendingMessages,
	(uint64_t)&__KLIB__MSGGetClientPendingMessages
};

// IRQ control table
uint64_t __KLIB__IRQ_control_table[16] =
{
	0,
	(uint64_t)&__KLIB__ISRReserve,
	(uint64_t)&__KLIB__ISRFree,
	(uint64_t)&__KLIB__GetGSIFromISA,
	(uint64_t)&__KLIB__GSIFree,
	(uint64_t)&__KLIB__GSIReserve,
	(uint64_t)&__KLIB__ISRRegister,
	(uint64_t)&__KLIB__ISRUnregister,
	(uint64_t)&__KLIB__IOAPIC_mask_IRQ,
	(uint64_t)&__KLIB__IOAPIC_unmask_IRQ,
	(uint64_t)&__KLIB__IOAPIC_get_IRQ_reg_dump,
	(uint64_t)&__KLIB__IOAPIC_manual_reg_write,
	(uint64_t)&__KLIB__GetMSIDestination
};

// keyboard buffer access table
uint64_t __KLIB__keyboard_buffer_table[16] =
{
	0,
	(uint64_t)__KLIB__KBBufferWrite,
	(uint64_t)__KLIB__KBBufferRead,
	(uint64_t)__KLIB__KBRegisterDriver,
	(uint64_t)__KLIB__KBUnregisterDriver,
	(uint64_t)__KLIB__KBReset,
	(uint64_t)__KLIB__KBSetNumLED,
	(uint64_t)__KLIB__KBSetCapLED,
	(uint64_t)__KLIB__KBSetScrLED
};

// ACPI tables table
uint64_t __KLIB__ACPI_table_table[8] =
{
	0,
	(uint64_t)__KLIB__ACPIGetMADTBase,
	(uint64_t)__KLIB__ACPIGetFADTBase,
	(uint64_t)__KLIB__ACPIGetDSDTBase,
	(uint64_t)__KLIB__ACPIGetHPETBase,
	(uint64_t)__KLIB__SystemConfigLock,
	(uint64_t)__KLIB__SystemConfigUnlock,
	(uint64_t)__KLIB__GetSystemConfigBase
};

// system timer control table
uint64_t __KLIB__system_timer_table[8] =
{
	0,
	(uint64_t)__KLIB__RegisterSchedulerTimer,
	(uint64_t)__KLIB__UnregisterSchedulerTimer,
	(uint64_t)__KLIB__PauseSchedulerTimer,
	(uint64_t)__KLIB__StartSchedulerTimer
};

// the system resources table
uint64_t __KLIB__system_resources_table[32] =
{
	0,
	(uint64_t)__KLIB__RCGetCPUUsage,
	(uint64_t)__KLIB__RCGetCPUActiveThreads,
	(uint64_t)__KLIB__RCGetTID,
	(uint64_t)__KLIB__RCGetPID,
	(uint64_t)__KLIB__RCGetProcs,
	(uint64_t)__KLIB__RCGetProcDetails,
	(uint64_t)__KLIB__RCGetProcImageName,
	(uint64_t)__KLIB__RCGetProcDescription,
	(uint64_t)__KLIB__RCGetThreads,
	(uint64_t)__KLIB__RCGetProcMemory,
	(uint64_t)__KLIB__SystemTimeGetYear,
	(uint64_t)__KLIB__SystemTimeGetMonth,
	(uint64_t)__KLIB__SystemTimeGetDay,
	(uint64_t)__KLIB__SystemTimeGetHour,
	(uint64_t)__KLIB__SystemTimeGetMinute,
	(uint64_t)__KLIB__SystemTimeGetSecond,
	(uint64_t)__KLIB__SystemTimeGetMSecond,
	(uint64_t)__KLIB__SystemTimeGetSecondSincEpoc,
	(uint64_t)__KLIB__SystemTimeGetMSecondSinceEpoc
};


// the ACDM module table (links directly to the module)
uint64_t __KLIB__ACDM_module_table[32] =
{
	0,
	(uint64_t)ACDMCreateStaticWindow,
	(uint64_t)ACDMDestroyWindow,
	(uint64_t)ACDMDestroyWindowsForProc,
	(uint64_t)ACDMWindowHide,
	(uint64_t)ACDMWindowShow,
	(uint64_t)ACDMWindowUpdate,
	(uint64_t)ACDMWindowChangeName,
	(uint64_t)ACDMWindowWaitForFocus,
	(uint64_t)ACDMWindowGetBufferAddress,
	(uint64_t)ACDMGetWindowsForProc,
	(uint64_t)ACDMWindowWaitForChar,
	(uint64_t)ACDMWindowClearChar,
	(uint64_t)ACDMWindowGetKeystate,
	(uint64_t)ACDMLogin,
	(uint64_t)ACDMGiveFocus,
	(uint64_t)ACDMPrintLog
};

// the PCIE control table
uint64_t __KLIB__PCIE_control_table[16] =
{
	0,
	(uint64_t)__KLIB__PCIEGetDeviceCount,
	(uint64_t)__KLIB__PCIEGetDevices,
	(uint64_t)__KLIB__PCIEGetDeviceCountOfClass,
	(uint64_t)__KLIB__PCIEGetDevicesOfClass,
	(uint64_t)__KLIB__PCIEGetDeviceAddress,
	(uint64_t)__KLIB__PCIEGetDeviceIDs,
	(uint64_t)__KLIB__PCIEReserveDevice,
	(uint64_t)__KLIB__PCIEFreeDevice,
	(uint64_t)__KLIB__PCIEConfigRead,
	(uint64_t)__KLIB__PCIEConfigWrite
};

// the global table
uint64_t __KLIB__function_group_array[128] =
{
	0,
	(uint64_t)__KLIB__proc_threads_table,
	(uint64_t)__KLIB__page_alloc_table,
	(uint64_t)__KLIB__message_passing_table,
	(uint64_t)__KLIB__IRQ_control_table,
	(uint64_t)__KLIB__keyboard_buffer_table,
	(uint64_t)__KLIB__ACPI_table_table,
	(uint64_t)__KLIB__system_timer_table,
	(uint64_t)__KLIB__system_resources_table,
	(uint64_t)__KLIB__ACDM_module_table,
	(uint64_t)__KLIB__PCIE_control_table
};


















